package ming.model.base;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import ming.model.type.Terminal;

@SuppressWarnings("serial")
@Entity
@Table(name = "TBUSER", schema = "")
@DynamicInsert(true)
@DynamicUpdate(true)
public class User implements java.io.Serializable {

	private String ip;// 此属性不存数据库，虚拟属性
	private String roleSelect;// 此属性不存数据库，虚拟属性
	private Role role; // 此属性不存数据库，虚拟属性
	private String validateCode; // 此属性不存数据库，虚拟属性
	private String password; // 此属性不存数据库，虚拟属性
	private String flag;// 此属性不存数据库，虚拟属性 是否保存密码

	private String vcclasses;
	private String vcgrade;
	private String vccolname;
	private String vcmajor;
	
	
	private String id;
	private Date createdatetime;
	private Date updatedatetime;
	private String loginname;
	private String pwd;
	private String name;
	private String sex;
	private String phoneNum;
	private Integer paperAlertStatus;
	private Integer faultAlertStatus;
	private String msSendTime;
	private Set<Organization> organizations = new HashSet<Organization>(0);
	private Set<Role> roles = new HashSet<Role>(0);
	private Set<Terminal> terminals = new HashSet<Terminal>(0);

	@Id
	@Column(name = "ID", unique = true, nullable = false, length = 36)
	public String getId() {
		if (!StringUtils.isBlank(this.id)) {
			return this.id;
		}
		return UUID.randomUUID().toString();
	}

	public void setId(String id) {
		this.id = id;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATEDATETIME", length = 7)
	public Date getCreatedatetime() {
		if (this.createdatetime != null)
			return this.createdatetime;
		return new Date();
	}

	public void setCreatedatetime(Date createdatetime) {
		this.createdatetime = createdatetime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATEDATETIME", length = 7)
	public Date getUpdatedatetime() {
		if (this.updatedatetime != null)
			return this.updatedatetime;
		return new Date();
	}

	public void setUpdatedatetime(Date updatedatetime) {
		this.updatedatetime = updatedatetime;
	}

	@Column(name = "LOGINNAME", nullable = false, length = 100)
	public String getLoginname() {
		return this.loginname;
	}

	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}

	@Column(name = "PWD", length = 100)
	public String getPwd() {
		return this.pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	@Column(name = "NAME", length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "SEX", length = 1)
	public String getSex() {
		return this.sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "phoneNum", length = 200)
	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	@Column(name = "paperAlertStatus", length = 1)
	public Integer getPaperAlertStatus() {
		return paperAlertStatus;
	}

	public void setPaperAlertStatus(Integer paperAlertStatus) {
		this.paperAlertStatus = paperAlertStatus;
	}
	
	@Column(name = "faultAlertStatus", length = 1)
	public Integer getFaultAlertStatus() {
		return faultAlertStatus;
	}

	public void setFaultAlertStatus(Integer faultAlertStatus) {
		this.faultAlertStatus = faultAlertStatus;
	}
	
	@Column(name = "dtMsSendTime", length = 19)
	public String getMsSendTime() {
		return msSendTime;
	}

	public void setMsSendTime(String msSendTime) {
		this.msSendTime = msSendTime;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "TBUSER_ORGANIZATION", schema = "", joinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ORGANIZATION_ID", nullable = false, updatable = false) })
	public Set<Organization> getOrganizations() {
		return this.organizations;
	}

	public void setOrganizations(Set<Organization> organizations) {
		this.organizations = organizations;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "TBUSER_ROLE", schema = "", joinColumns = { @JoinColumn(name = "USER_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) })
	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	@Transient
	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}
	@Transient
	public String getRoleSelect() {
		return roleSelect;
	}

	public void setRoleSelect(String roleSelect) {
		this.roleSelect = roleSelect;
	}
	@Transient
	public String getValidateCode() {
		return validateCode;
	}

	public void setValidateCode(String validateCode) {
		this.validateCode = validateCode;
	}
	@Transient
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Transient
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Transient
	public String getVcclasses() {
		return vcclasses;
	}

	public void setVcclasses(String vcclasses) {
		this.vcclasses = vcclasses;
	}
	@Transient
	public String getVcgrade() {
		return vcgrade;
	}

	public void setVcgrade(String vcgrade) {
		this.vcgrade = vcgrade;
	}
	@Transient
	public String getVccolname() {
		return vccolname;
	}

	public void setVccolname(String vccolname) {
		this.vccolname = vccolname;
	}
	@Transient
	public String getVcmajor() {
		return vcmajor;
	}

	public void setVcmajor(String vcmajor) {
		this.vcmajor = vcmajor;
	}

	@Transient
	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_tobacco_user_terminal", schema = "", joinColumns = { @JoinColumn(name = "vcUser_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "vcTerminal_ID", nullable = false, updatable = false) })
	public Set<Terminal> getTerminals() {
		return this.terminals;
	}

	public void setTerminals(Set<Terminal> terminals) {
		this.terminals = terminals;
	}
	

}
